/**
 * Copyright (c) Martijn Grootens (m.e.grootens@student.utwente.nl), 
 * University of Twente.
 * Created july 2012.
 *
 * This file is part of dbcleaner.
 * 
 * dbcleaner is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * dbcleaner is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with dbcleaner.  If not, see <http://www.gnu.org/licenses/>.
 */

package dbcleaner.core.bibfields;

import java.util.*;

/**
 * Representation of a BibTex field. 
 * A field has a name, e.g. "title", and an entry (also called contents), 
 * e.g. "Very interesting story".
 */
public class BibField {
    
    // A BibField without entry is set to EMPTY.
    public static final String EMPTY = "EMPTY";
    
    // The single (case insensitive) forbidden field entry. This could
    // also be replaced by an ArrayList of multiple forbidden entries.
    // Currently xxx seems the only often occuring entry.
    private static final String FORBIDDEN = "xxx";
    
    // Name and entry (contents) of the BibField.
    private String field_name;
    private String field_entry;
    
    /**
     * Constructor for a complete BibField, i.e. with name and entry.
     */
    public BibField (String name, String entry) {
        this.set_field_name(name);
        this.set_field_entry(entry);
    }
    
    /**
     * Constructor for a BibField with name, but without field entry.
     */
    public BibField (String name) {
        this(name,EMPTY);
    }
    
    /**
     * Return BibField field_name.
     */
    public String get_field_name () {
        return field_name;
    }
    
    /**
     * Return BibField field entry (i.e. its contents).
     */
    public String get_field_entry () {
        return field_entry;
    }
    
    /**
     * Set BibField field name.
     */
    public void set_field_name (String name) {
        this.field_name = name;
    }
    
    /**
     * Set BibField entry (contents). 
     * If the FORBIDDEN string is passed, set it to EMPTY.
     */
    public void set_field_entry (String entry) {
        
        if (entry.equalsIgnoreCase(FORBIDDEN))
            this.field_entry = EMPTY;
        else 
            this.field_entry = entry;
        
    }
    
    /**
     * Append a String to this BibField entry.
     */
    public void append_to_field_entry (String append) {
        this.set_field_entry(this.get_field_entry() + append);
    }
    
    /**
     * Print the BibField in BibTeX format.
     */
    public String toString () {
        
        return "\t" + this.get_field_name() +
        " = {" + this.get_field_entry() + "},\n";
        
    }
    
    
}